#include "main.h"


sterilization_setting::sterilization_setting(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::sterilization_setting)
{
    ui->setupUi(this);

}

sterilization_setting::~sterilization_setting()
{
    delete ui;

}

void sterilization_setting::entrance()
{

   switch(sterilization_protype)
   {
   case TEXTITLES_PROTYPE:  data=&textiles_config;
       ui->lineEdit->setText(QString::fromUtf8("织物类"));
       break;
   case METALS_PROTYPE:     data=&metals_config;
       ui->lineEdit->setText(QString::fromUtf8("器械类"));
       break;
   case USER_DEFINE_1:      data=&user_define1_config;
       ui->lineEdit->setText(QString::fromUtf8("自定义真空1"));
       break;
   case USER_DEFINE_2:      data=&user_define2_config;
       ui->lineEdit->setText(QString::fromUtf8("自定义真空2"));
       break;
   case USER_DEFINE_3:      data=&user_define3_config;
       ui->lineEdit->setText(QString::fromUtf8("自定义真空3"));
       break;

   }
   display();
   showFullScreen();
}

void sterilization_setting::display()
{

   ui->sterilization_temperature->setText(  QString::number(data->sterilization_temperature));
   ui->sterilization_time->setText(         QString::number(data->sterilization_time));
   ui->pulsing_times->setText(              QString::number(data->pulsing_times));
   ui->pulsing_lowest_pressure->setText(    QString::number(data->pulsing_lowest_pressure));
   ui->pulsing_highest_pressure->setText(    QString::number(data->pulsing_highest_pressure));
   ui->prebalance_time->setText(             QString::number(data->prebalance_time));
   ui->dry_pressure->setText(                QString::number(data->dry_pressure));
   ui->dry_keep_time->setText(               QString::number(data->dry_keep_time));
   ui->dry_times->setText(                   QString::number(data->dry_times));


}



void sterilization_setting::on_buttonBox_accepted()
{
    BUTTON_SOUND;
    getvalue();
   config_changed=true;
   stype->showFullScreen();
   this->close();

}

void sterilization_setting::on_buttonBox_rejected()
{
      BUTTON_SOUND;
      stype->showFullScreen();
     this->close();
}

void sterilization_setting::getvalue()
{
        int input=ui->sterilization_temperature->text().toInt();
        if( verify(input, 105,136,"灭菌温度必须在105～136 范围内"))
        data->sterilization_temperature= input;

        input=ui->sterilization_time->text().toInt();
        if( verify(input, 0,18000,"灭菌时间必须在0～18000s 范围内"))
        data->sterilization_time=input;

        input=ui->pulsing_times->text().toInt();
        if( verify(input, 0,6,"脉动次数必须在0～6 范围内"))
        data->pulsing_times=input;

        input=ui->pulsing_highest_pressure->text().toInt();
        if( verify(input, 0,200,"脉动压力上限必须在0～200 范围内"))
        data->pulsing_highest_pressure= input;

        input=ui->pulsing_lowest_pressure->text().toInt();
        if( verify(input, -95,0,"脉动压力下限必须在 -95～0 范围内"))
        data->pulsing_lowest_pressure=input;

        input=ui->prebalance_time->text().toInt();
        if( verify(input, 0,1800,"预平衡时间必须在0～1800 s范围内"))
        data->prebalance_time=input;

        input=ui->dry_times->text().toInt();
        if( verify(input, 0,3, "干燥次数必须在0～3 范围内"))
        data->dry_times=input;

        input=ui->dry_pressure->text().toInt();
        if( verify(input, -95,0, "干燥压力必须在-95～0 范围内"))
        data->dry_pressure=input;

        input=ui->dry_keep_time->text().toInt();
        if( verify(input, 0,3600, "干燥时间必须在0～3600s 范围内"))
        data->dry_keep_time=input;

}

bool sterilization_setting::verify(int value, int low, int high, const char* tips)
{

    if(value < low || value >high) {
        QMessageBox::warning(this,QString::fromUtf8("输入非法！"),QString::fromUtf8(tips));
        return FALSE;
        }
    else return TRUE;
}
